import javax.swing.*;
import java.awt.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
//        System.out.println("Hello world!");
//        Main.print_1();
//        Main.print_2();
//        MyFrame frame = new MyFrame();

        Test31 actor = new Test31();
        new Thread(actor, "Actor").start();
        new Thread(actor, "Actor").start();
        new Thread(actor, "Actor").start();
        new Thread(actor, "Actor2").start();
    }

    private static void print_1() {
        for(int k=0; k<5; k++) {
            System.out.println("Are you finished yet?");
        }
        System.out.println("Finally!");
    }

    private static void print_2() {
        int k=0;
        while (k<5) {
            k++;
            System.out.println("Are you finished yet?");
        }
        System.out.println("Finally!");
    }

    static class MyPanel extends JPanel {
        public void paintComponent(Graphics g) {
            g.setColor(Color.green);
//            g.drawArc(200,200, 100,100,0,360);
            g.drawOval(100,100,200,200);
            g.setColor(Color.red);
//            g.drawArc(200,200, 50,50,0,360);
            g.drawOval(150,150,100,100);
        }
    }

    static class MyFrame extends JFrame {
        public MyFrame() {
            setTitle("Test28");
            setSize(400,400);
            getContentPane().add(new MyPanel());
            setVisible(true);
        }
    }

    static class Test31 implements Runnable {
        private int task=5;

        @Override
        public void run() {
            while(task > 0) {
                try{
                    Thread.sleep(30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized(this) {
                    System.out.println(Thread.currentThread().getName() + ": 完成第" +(task--) + "项任务");
                }
            }
        }
    }

    private static void scanner() {
        int i,j;
        Scanner sc = new Scanner(System.in);
        System.out.println("输入一个正整数：");
        i = sc.nextInt();
        while (sc.hasNext()) {
            j = sc.nextInt();
            System.out.println(j);

        }
    }
}